#
#将麦系统中自从2018年就没有更新过得商品在派系统中禁用商品的生产标准更新为派系统商品的备注
#
#需要在.bahs_profile设置环境变量
#export PSI_PASSWORD=xxxxxxx
#export RDS_AGENT=yyyy
#
#手工在命令行运行 ruby disable*.rb
#
require 'mysql2'

rds = Mysql2::Client.new(:host => ENV['RDS_AGENT'], :username => "psi_root", :port => '1401', :password => ENV['PSI_PASSWORD'])

sql1 = "select * from psi.m_product where updated_at < '2018-01-01'"
res1 = rds.query(sql1)

res1.each do |tgr|
    code = tgr['sku']
    name = tgr['product_name']
    if code
        sql2 = "update psi.t_goods set record_status=0 where code = '#{code}'"
        puts "disabling #{name}: " + sql2
        #res2 = rds.query(sql2)
    end
end

rds.close
